package com.yangye.pisystem.controller;

import com.yangye.picommon.model.PiResult;
import com.yangye.picommon.model.page.PageRequest;
import com.yangye.picommon.model.page.PageResult;
import com.yangye.pisystem.domain.SysDictData;
import com.yangye.pisystem.service.SysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
* @author yangye
* @date 2020-3-18
* 自动生成代码
*/
@RestController
@RequestMapping("sys/dictdata")
public class SysDictDataController {

    @Autowired
    private SysDictDataService sysDictDataService;

    /**
    * 新增
    * @param sysDictData
    * @return
    */
    @PostMapping("/")
    @PreAuthorize("hasAuthority('sys:dict:add')")
	PiResult add(@RequestBody SysDictData sysDictData) {
        sysDictDataService.add(sysDictData);
        return PiResult.succeed();
    }

    /**
    * 删除
    * @param id
    * @return
    */
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAuthority('sys:dict:remove')")
	PiResult remove(@PathVariable Long id) {
        sysDictDataService.remove(id);
        return PiResult.succeed();
    }

    /**
    * 修改
    * @param sysDictData
    * @return
    */
    @PutMapping("/")
    @PreAuthorize("hasAuthority('sys:dict:update')")
	PiResult update(@RequestBody SysDictData sysDictData) {
        sysDictDataService.update(sysDictData);
        return PiResult.succeed();
    }

    /**
    * 查看详情
    * @param id
    * @return
    */
    @GetMapping("/{id}")
    @PreAuthorize("hasAuthority('sys:dict:view')")
	PiResult get(@PathVariable Long id) {
        SysDictData sysDictData = sysDictDataService.get(id);
        return PiResult.succeed(sysDictData);
    }

    /**
    * 查看分页
    * @param sysDictData
    * @param pageRequest
    * @return
    */
    @GetMapping("/page")
    @PreAuthorize("hasAuthority('sys:dict')")
	PiResult listPage(SysDictData sysDictData, PageRequest pageRequest) {
    PageResult<SysDictData> page = sysDictDataService.findPage(sysDictData, pageRequest);
        return PiResult.succeed(page);
    }
}